package com.example.livebroadcast.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.example.livebroadcast.dao.UserRedisDAO;
import com.example.livebroadcast.model.UserRedis;

@Service
public class UserService {
	
	@Autowired
	private UserRedisDAO userRedisDAO;
	
	public List<UserRedis> getAll(){
		List<UserRedis> list = userRedisDAO.getAll();
		return list;
	}
	
	public void save(UserRedis user) {
		userRedisDAO.put(user.getName(), user, -1);
	}
	
	public boolean isUser(UserRedis userRedis) {
		boolean isUser = true;
		UserRedis user = userRedisDAO.get(userRedis.getName());
		if (user ==null) {
			isUser = false;
		} else {
			if (!userRedis.getPassword().equals(user.getPassword())) {
				isUser = false;
			}
		}
		return isUser;
	}
}
